<template>
  <view class="normal-login-container">
    <!--左侧输入框搜索-->
    <search placeholder="请输入车牌号" @input="inputChange">
      <view class="flex right20 align-center" slot="right">
        <!--右侧缩略搜索-->
        <uni-icons type="tune" :color="isAllEmpty(queryParams) ? '#333' : '#1890FF'" @click="handleOpen" size="25" />
        <!--新增-->
        <uni-icons type="plus-filled" color="#1890FF" size="30" @click="handleToAdd" />
      </view>
    </search>
    <mescroll-body @init="mescrollInit" @down="downCallback" @up="upCallback">
      <view class="item-wrap" v-for="(item, index) in list" :key="index" @click="goDetail(item)">
        <view class="title-wrap lineBottom10">
          <text>{{ item.carNo || '' }}</text>
        </view>
        <view class="flex-row align-stretch">
          <view class="flex-col flex1">
            <view class="text-line">
              <text class="text-name">报废处置编号:</text>
              <text>{{ item.vehicleDisposalScrapNo || '' }}</text>
            </view>
            <view class="text-line">
              <text class="text-name">品牌/车系/车型:</text>
              <text class="text-value"> {{ item.brandName | filterNull }} {{ item.seriesName | filterNull }} {{ item.modelName | filterNull }}</text>
            </view>
            <view class="text-line">
              <text class="text-name">车辆产权:</text>
              <text>{{ item.propertyRightName || '' }}</text>
            </view>
            <view class="text-line">
              <text class="text-name">审核状态:</text>
              <text class="text-value">{{ item.auditFlowStatus || '' }}</text>
            </view>
          </view>
        </view>
        <view class="btn-wrap lineTop20">
          <button size="mini" v-if="([0, 3].includes(Number(item.auditStatus)) && Number(item.source) === 0) || (Number(item.auditStatus) === 3 && Number(item.source) === 1)" @click.stop="handleDisposalNew(item)" type="primary">
            处置车辆
          </button>
        </view>
      </view>
    </mescroll-body>

    <condition-search ref="refConditionSearch" v-model="queryParams" @reset="reset" @confirm="confirm" />
  </view>
</template>

<script>
import ConditionSearch from './components/conditionSearch.vue'
import * as apis from '@/api/vehicleWarning'
export default {
  components: {
    ConditionSearch,
  },
  dicts: ['warning_state_type'],
  data() {
    return {
      list: [],
      queryParams: {
        vinNo: '',
        carNo: '',
        customerName: '',
        maintenanceNo: '',
        propertyRightName: '',
        createBy: '',
        startTime: '',
        endTime: '',
      },
    }
  },
  onLoad() {
    uni.$on('refBackList', call=>{
      this.mescroll.triggerDownScroll();
    })
  },
  methods: {
    //新增
    handleToAdd() {
      let url = `/pages/VehiclePage/vehicleScrap/add?type=add`
      this.$tab.navigateTo(url)
    },
    //车架 车牌
    inputChange(val) {
      this.queryParams.carNo = val
      this.mescroll.resetUpScroll()
    },

    //搜索
    isAllEmpty() {},

    //打开搜索弹框
    handleOpen() {
      this.$refs.refConditionSearch.open()
    },

    //获取列表
    async upCallback(page) {
      var params = {
        pageNum: page.num,
        pageSize: page.size,
        carNo: this.carNo,
        ...this.queryParams,
      }
      try {
        const res = await apis?.getList(params)
        //设置列表数据
        if (page.num === 1) this.list = [] //如果是第一页需手动制空列表
        this.list = this.list.concat(res.rows) //追加新数据
        this.mescroll.endBySize(res.rows.length, res.total)
      } catch (e) {
        //联网失败, 结束加载
        this.mescroll.endErr()
      }
    },

    goDetail(val) {
      let url = `/pages/VehiclePage/vehicleScrap/add?type=detail&id=${val.vehicleDisposalScrapId}&flowId=${val.flowId}`
      this.$tab.navigateTo(url)
    },

    reset() {
      this.queryParams = {}
      this.mescroll.resetUpScroll()
    },

    confirm(val) {
      this.queryParams = val
      this.mescroll.resetUpScroll()
    },
    handleDisposalNew(item) {
      let url
      if ([0, 3].includes(Number(item.auditStatus)) && Number(item.source) === 0) {
        url = `/pages/VehiclePage/vehicleScrap/add?type=ZD&id=${item.vehicleDisposalScrapId}&flowId=${item.flowId}`
      } else if (Number(item.auditStatus) === 3 && Number(item.source) === 1) {
        url = `/pages/VehiclePage/vehicleScrap/add?type=edit&id=${item.vehicleDisposalScrapId}&flowId=${item.flowId}`
      }
      this.$tab.navigateTo(url)
    },
  },
}
</script>

<style lang="scss" scoped>
.radio {
  display: flex;
  align-items: center;
  font-size: 26rpx;
  margin-left: 10rpx;
}

.sel-wrap {
  padding: 0 0 0 10rpx;
}
</style>
